package com.bingarchive;

import org.xml.sax.Attributes;

class BingParser extends AbstractParser {

	public static void Parser(String stXML, LoadParams loadParams, OnParserListener onParserListener) {
		BingXMLHandler _xmlHandler = new BingXMLHandler(loadParams, onParserListener);
		Parser(stXML, loadParams, _xmlHandler, onParserListener);
	}
	
	static class BingXMLHandler extends AbstractParser.XMLHandler {
		
		public BingXMLHandler(LoadParams loadParams,
				OnParserListener onParserListener) {
			super(loadParams, onParserListener);
		}

		private final String GROUP_IMAGE = "image";
		private final String ITEM_STARTDATE = "startdate";
		private final String ITEM_URL = "url";
		private final String ITEM_COPYRIGHT = "copyright";
//		private final String ITEM_DESC = "desc";
//		private final String ITEM_MSGTEXT = "msgtext";
		
		private String mstGroup = "";
		private String mstItem = "";
		
		@Override
		public void startElement(String uri, String localName, String qName,
				Attributes attributes) {
			if(qName.equals(GROUP_IMAGE)) {
				if(mstGroup.equals("")) {
//					mbtInfo = new BingType(new Date());
					mstGroup = GROUP_IMAGE;
				}
			} else {
				mstItem = qName;
			}
		}

		@Override
		public void endElement(String uri, String localName, String qName) {
			if(qName.equals(GROUP_IMAGE)) {
//				malImages.add(mbtInfo);
//				mbtInfo = null;
				mstGroup = "";
			} else {
				mstItem = "";
			}
		}

		@Override
		public void characters(char[] ch, int start, int length) {
			if(mstGroup.equals(GROUP_IMAGE)) {
				if(mstItem.equals(ITEM_STARTDATE)) {
//					mbtInfo.mstDate = String.valueOf(ch, start, length);
				} else if(mstItem.equals(ITEM_URL)) {
					String _stURL = String.valueOf(ch, start, length);
					mLoadParams.mbtInfo.mstName = _stURL.substring(_stURL.lastIndexOf('/') + 1);
//				} else if(mstItem.equals(ITEM_MSGTEXT)) {
//					if(mLoadParams.mbtInfo.mstTitle.equals("")) {
//						mLoadParams.mbtInfo.mstTitle = String.valueOf(ch, start, length);
//					}
//				} else if(mstItem.equals(ITEM_DESC)) {
//					mLoadParams.mbtInfo.malHotspots.add(String.valueOf(ch, start, length));
				} else if(mstItem.equals(ITEM_COPYRIGHT)) {
						mLoadParams.mbtInfo.mstCopyright = String.valueOf(ch, start, length);
				}
			}
		}
	}

}
